﻿using UnityEngine;
using System.Collections;
using System;

public class CameraBounds : MonoBehaviour
{
    //[SerializeField]
    //private Terrain ter = null;

    [SerializeField]
    private float paddingLeft = 0f;
    [SerializeField]
    private float paddingRight = 0f;
    [SerializeField]
    private float paddingTop = 0f;
    [SerializeField]
    private float paddingBttom = 0f;

    [NonSerialized]
    public float MinX = 0f;
    [NonSerialized]
    public float MaxX = 0f;
    [NonSerialized]
    public float MinZ = 0f;
    [NonSerialized]
    public float MaxZ = 0f;


    //TerrainCollider col = null;
    // Use this for initialization
    void Start()
    {
        //ter = Terrain.activeTerrain;

        //col = ter.GetComponent<TerrainCollider>();

        SetBounds();
    }

    void SetBounds()
    {
        MinX = /*col.bounds.min.x + */paddingLeft;
        MaxX = /*col.bounds.max.x - */paddingRight;
        MinZ = /*col.bounds.min.z + */paddingBttom;
        MaxZ = /*col.bounds.max.z - */paddingTop;
    }

    public void MoveBounds(Vector3 direction)
    {
        paddingLeft += direction.x;
        paddingRight += direction.x;
        paddingTop += direction.z;
        paddingBttom += direction.z;

        SetBounds();
    }

    public void SetBounds(float left, float right, float up, float down)
    {
        paddingLeft = left;
        paddingRight = right;
        paddingTop = up;
        paddingBttom = down;
        SetBounds();
    }

#if UNITY_EDITOR
    private void OnValidate()
    {
        //if (col != null)
        {
            SetBounds();
        }
    }
#endif
}
